#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+10;
ll n,t,b[maxn],cp[maxn];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        ll ans=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>cp[i];
        }
        for(int i=2;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(cp[i]==cp[j]){
                    ans+=cp[i];
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
